<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改信息</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">业务管理</a>
        <a href="#">业务分部</a>
        <a href="#">编辑代理人信息</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form class="layui-form" style="width: 500px;padding-top: 20px" id="up" onsubmit="return false">
    <input value="{$result.id}" name="id" hidden>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理姓名</label>
        <div class="layui-input-block" >
            <input type="text" name="name" value="{$result.name}" placeholder="{$result.name}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" value="{$result.phone}" readonly placeholder="{$result.phone}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理电话</label>
        <div class="layui-input-block">
            <input type="text" name="tel" value="{$result.tel}" placeholder="{$result.tel}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">详细地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" value="{$result.address}" placeholder="{$result.address}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" value="{$result.remark}" placeholder="{$result.remark}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" value="{$result.email}" placeholder="{$result.email}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px">代理类型</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="aihao">
                <option value="{$result.get_type.id}">{$result.get_type.name}</option>
                {foreach $type as $val}
                <option value="{$val.id}">{$val.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="sub" lay-submit lay-filter="*">立即提交</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use('layer',function(){
        layer = layui.layer;
    });
</script>
<script>
    $("#sub").click(function() {
        //正则
        var phone_rule = /^1(3|4|5|7|8)\d{9}$/;
        var email_rule = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;

        var phone = $("#phone").val();
        var email = $("#email").val();


        // if (!phone_rule.test(phone)) {
        //     layer.msg('手机号不符合规范', {icon: 5, time: 2000});
        //     return;
        // }
        // if (!email_rule.test(email)) {
        //     layer.msg('邮箱不符合规范', {icon: 5, time: 2000});
        //     return;
        // }

        $.ajax({
            url: "{:url('/customer/updateCustomer')}",
            data: $("#up").serialize(),
            type: "post",
            dataType: "json",
            success: function (res) {
                if (res.code) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                        window.location.reload();
                    });
                    return;
                } else {
                    layer.msg(res.msg, {icon: 5, time: 2000});
                    return;
                }
            }
        })
    })

    $("#back").click(function () {
        window.history.go(-1)
    })
</script>